package com.example.pureman.myapplication;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by kkkkk on 2016/4/19.
 */
public class MainFragment extends BaseFragment {

    public interface OnSeasonSelectedListener {
        public void onSeasonSelected(Season season);
    }

    private OnSeasonSelectedListener onSeasonSelectedListener;
    private Season currentSeason;

    private static String USER_SELECTION = "USER_SELECTION";
    private int userSelection = 0;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        try {
            onSeasonSelectedListener = (OnSeasonSelectedListener) context;
        } catch (ClassCastException e) {
            throw new ClassCastException(context.toString() +
                    " must implement OnSeasonSelectedListener");
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);
        if (savedInstanceState != null)
            userSelection = savedInstanceState.getInt(USER_SELECTION);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putInt(USER_SELECTION, userSelection);
        super.onSaveInstanceState(outState);
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    private void setSeason(Season season) {
        currentSeason = season;
        onSeasonSelectedListener.onSeasonSelected(season);
    }
}
